package Coffee.service;

import Coffee.bean.Coffee;
import Coffee.dao.CoffeeDao;
import Coffee.dao.CoffeeDaoImpl;

import java.util.List;

public class CoffeeServiceImpl implements CoffeeService{
    CoffeeDao coffeeDao = new CoffeeDaoImpl();
    @Override
    public int insertCoffee(Coffee coffee) {
        Coffee selectbyname = coffeeDao.selectbyname(coffee.getCofname());
        int i = 0;
        if(selectbyname != null){
            System.out.println("已经有该饮品了");
        }else{
             i =  coffeeDao.insertCoffee(coffee);
        }
        if(i == 1){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
        return i;
    }

    @Override
    public int delbyname(String cofname) {
        int i = coffeeDao.delbyname(cofname);
        if(i==1){
            System.out.println("删除成功");
        }else {
            System.out.println("没有该饮品的上架信息");
        }
        return i;
    }

    @Override
    public Coffee selectbyname(String cofname) {
        Coffee selectbyname = coffeeDao.selectbyname(cofname);
        if(selectbyname == null){
            System.out.println("该饮品还未上新");
        }
        return selectbyname;
    }

    @Override
    public int updateCofbyname(String cofname, int cofprice, String state) {
        int i = coffeeDao.updateCofbyname(cofname, cofprice, state);
        if(i==1){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
        return i;
    }

    @Override
    public List<Coffee> selectlikaname(String cofname) {
        return coffeeDao.selectlikaname(cofname);
    }

    @Override
    public List<Coffee> selectAll() {
        return coffeeDao.selectAll();
    }
}
